// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    canIUseGetUserProfile: false,
    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), // 如需尝试获取用户信息可改为false
    token: ''
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  // editInfo(e){
  //   wx.navigateTo({
  //     url: '/pages/me/info/info',
  //   })
  // },
  doLogin(){
    var _this = this
    console.log("绑定微信")

    _this.getCodeAndUuid()

    wx.request({
      url: 'http://localhost:8080/login',
      method:'POST',
      data:{
        username: 'admin',
        password: 'admin123',
        code: '4',
        uuid: '4353704c7a8641b48aaf19e9b0e81f55'
      },
      header:{
        'content-type': 'application/json'
      },
      success:function(res){
        console.log(res)
        
        _this.setData({
          token: res.data.token
        })
      }
    })
  },
  ToLoginPage(){
    wx.navigateTo({
      url: '/pages/me/login/login',
    })
  },
  getUserInfo() {
    app.getUserInfo()
  },
  onLoad() {
    var that = this
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
    this.data.userInfo = app.globalData.userInfo
    console.log(this.data.userInfo)
    // 更改数据后 要调用 setData 才能渲染到页面
    this.setData({
      userInfo: this.data.userInfo
    })


  },

  logout() {
    app.sendPostRequest("/logout",null, (res)=>{
      if (res.code == 200) {
        wx.showToast({
          title: '退出成功',
          duration: 2000
        })
      }
    })
  },

  onShow(){
  }
})